package com.lrm.web;

import com.lrm.biz.IBlogBiz;
import com.lrm.biz.ICommentBiz;
import com.lrm.pojo.Comment;
import com.lrm.util.Result;
import com.lrm.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 王金海
 * @Description: 评论
 * @Date: Created by Administrator on 2017/12/6.
 * @Modified By:
 */
@RestController
@RequestMapping("comment")
public class CommentController {

    @Value("${comment.avatar}")
    private String avatar;

    @Autowired
    private ICommentBiz commentBiz;

    @Autowired
    private IBlogBiz blogBiz;

    @GetMapping("/listComment/{blogId}")
    public Result listComment(@PathVariable Long blogId){
        List<Comment> comments = commentBiz.listComment(blogId);
        return ResultUtil.success(comments);
    }

    @PostMapping("/addComment")
    public Result addComment(Comment commentone){
        Long id = commentone.getBlog().getId();
        commentone.setBlog(blogBiz.getOne(id));
        commentone.setAvatar(avatar);
        Comment save = commentBiz.addComment(commentone);
        return ResultUtil.success(save);
    }
}
